<template>
    <view>
        <view v-if="!isLoad" class="margin-top load loading text-l text-work"></view>

        <view class="main-work" v-if="isLoad && isWork">
            <view class="work-info bg-work">
                <view class="pic">
                    <image mode="aspectFill" class="loading" :src="work.avatar || '../../../../images/work/pic.png'" />
                </view>
                <view class="right">
                    <view class="name">
                        <text class="text-xl">{{ work.userName || '' }}</text>
                    </view>
                    <view v-if="work.loginCount" class="desc text-s">共登录{{ work.loginCount }}次，上次{{ work.lastLoginTime }}</view>
                    <view v-else class="desc text-s">首次登录~</view>
                </view>
                <view class="exit-work" @tap="bindExitTap"><text class="icon-exit"></text></view>
            </view>

            <view class="mid">
                <view class="main-menu" style="margin-top: 30rpx">
                    <view class="item" @tap="url" :data-url="'/pages/work/meet/edit/work_meet_edit?id=' + teacherId">
                        <view class="ico">
                            <view v-if="stat" class="status">{{ stat.dayCnt }}</view>
                            <text class="icon-calendar"></text>
                        </view>
                        <view class="desc">预约设置与排期</view>
                    </view>
                    <view class="item" @tap="url" :data-url="'/pages/work/meet/record/work_meet_record?meetId=' + teacherId">
                        <view class="ico">
                            <text class="icon-form"></text>
                        </view>
                        <view class="desc">用户预约记录</view>
                    </view>
                    <view class="item" @tap="url" :data-url="'/pages/work/meet/scan/work_meet_scan?meetId=' + teacherId">
                        <view class="ico">
                            <text class="icon-scan"></text>
                        </view>
                        <view class="desc">核销预约</view>
                    </view>
                </view>

                <view class="main-menu" style="margin-top: 30rpx">
                    <view class="item" @tap="url" data-url="/pages/work/index/pwd/work_pwd">
                        <view class="ico">
                            <text class="icon-edit"></text>
                        </view>
                        <view class="desc">修改登录密码</view>
                    </view>
                    <view class="item" @tap="url" :data-url="'/pages/meet/detail/meet_detail?id=' + teacherId">
                        <view class="ico">
                            <text class="icon-attention"></text>
                        </view>
                        <view class="desc">预览预约页面</view>
                    </view>
                </view>

                <view @tap="bindExitTap" class="btn-work btn-exit" style="border-radius: 20rpx">退出登录</view>
            </view>

            <view style="height: 150rpx"></view>
        </view>
    </view>
</template>

<script>
const WorkBiz = require('@/utils/biz/work_biz.js');
const pageHelper = require('@/utils/helper/page_helper.js');
const cloudHelper = require('@/utils/helper/cloud_helper.js');
const api = require('@/api/workapi.js');
export default {
    data() {
        return {
            id: '',
            isLoad: false,
            teacherId: '',
            work: {
                pic: '',
                name: '',
                cnt: '',
                last: ''
            },

            stat: {
                dayCnt: '11'
            },

            isWork: ''
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: async function (options) {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: async function () {
        await this.loadDetailFun();
        uni.stopPullDownRefresh();
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: async function () {
        if (!WorkBiz.isWork(this)) {
            this.setData({
                isLoad: false
            });
            return;
        }

        // 用于修改图片后更新展示
        let work = WorkBiz.getWorkToken();
        this.isLoad = true;
        this.work  = work.userInfo;
        this.id = work.userInfo.id;
        // this.setData({
        //     isLoad: true,
        //     work,
        //     id: work.id
        // });
        await this.loadDetailFun();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    methods: {
        loadDetailFun: async function () {
            try {
                let opts = {
                    title: 'bar'
                };
                api.getWorkHome().then((res) => {
                    console.log('res', res);
                    this.setData({
                        stat: res,
                        teacherId: res.teacherId
                    });
                });
                // let res = null;
                // this.setData({
                //     stat: res
                // });
            } catch (err) {
                console.log('CatchClause', err);
                console.log('CatchClause', err);
                console.log(err);
            }
        },

        url: function (e) {
            pageHelper.url(e, this);
        },

        bindExitTap: function (e) {
            let callback = function () {
                WorkBiz.clearWorkToken();
                uni.reLaunch({
                    url: '/pages/my/index/my_index'
                });
            };
            pageHelper.showConfirm('您确认退出?', callback);
        }
    }
};
</script>
<style>
@import './work_home.css';
</style>
